<?php

namespace App;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class TeamActivity extends Model
{
    protected $fillable = ['time_limit', 'title', 'discount', 'goods_id', 'goods_name', 'sales_sum', 'virtual_num', 'order', 'status', 'bonus', 'needer', 'type'];

    public function goods()
    {
        return $this->belongsTo('App\Goods');
    }
    // 有效的的拼团活动
    public function scopeOfActive($query)
    {
        return $query->where('status', 1);
    }

    public function activeFounds()
    {
        return $this->hasMany('App\TeamFound')
            ->where('status', 'ACTIVE')
            ->where('ended_at', '>', Carbon::now())
            ->with('user')
            ->limit(10);
    }
}
